<template>
  <div style="width: 100%;height:100%">
    <welone v-if="UserInfo.role=='管理员' || UserInfo.role=='业务员'"
      :bonustol="bonustol"
      :rechargetol="rechargetol" 
      :deletol="deletol"
      :points="points"
      :ftotal="ftotal"
      :mbonustol="mbonustol"
      :mrechargetol="mrechargetol"
      :mdeletol="mdeletol"
    >
    </welone>
    <weltwo v-if="UserInfo.role=='渠道主'"
      :bonustol="(UserInfo.message+UserInfo.bonus_points)/10000"
      :rechargetol="UserInfo.message/10000"
      :deletol="UserInfo.bonus_points/10000"
      :priceList="priceList"
    >
    </weltwo>
    <welthree v-if="UserInfo.role=='代理商'"
      :bonustol="(UserInfo.message+UserInfo.bonus_points)/10000"
      :rechargetol="UserInfo.message/10000"
      :deletol="UserInfo.bonus_points/10000"
      :priceList="priceList"
      :list="list"
      :totalCnt="totalCnt"
    >
    </welthree>
  </div>
</template>

<script>
import utils from "../commons/utils";
import Request from "../commons/Request"
import welone from "../views/welcome/welone.vue"
import weltwo from "../views/welcome/weltwo.vue"
import welthree from "../views/welcome/welthree.vue"
import { mapGetters } from "vuex";
export default {
  name: "welcome",
  components:{welone,weltwo,welthree},
  data() {
    return {
      date:new Date,
      month:new Date,
      firstDay:'',
      lastDay:'',
      show:2,
      msg: "Welcome to 管理平台",
      list:[],
      bonus:[],
      recharge:[],
      bonustol:'',
      rechargetol:'',
      deletol:'',
      points:'',
      ftotal:'',
      mbonustol:'',
      mrechargetol:'',
      mdeletol:'',   
      priceList:[],
      list:[],
      totalCnt:0,
      wsskt:require('../assets/images/peach-svg/homepage/wsskt.svg'),
      amazon:require('../assets/images/peach-svg/homepage/amazon.svg'),
      fb:require('../assets/images/peach-svg/homepage/fb.svg'),
      ins:require('../assets/images/peach-svg/homepage/ins.svg'),
      lin:require('../assets/images/peach-svg/homepage/lin.svg'),
      viber:require('../assets/images/peach-svg/homepage/viber.svg'),
    };
  },
  computed:{ 
    ...mapGetters(["UserInfo"]),
  },
  methods: {
    async initView() {
      this.$store.dispatch("RequestSysDefine",true);
      this.$store.dispatch("RequestUserInfo",true);
      await this.getList();
    },
    async getList(){
      //当天 yyyy-MM-dd
      this.date = Date.parse(this.date)/1000;  
      this.date = utils.dateFormat(this.date,"yyyy-MM-dd")
      
      //本月 yyyy-MM-dd，yyyy-MM-dd
      var currentMonth = this.month.getMonth()
      var firstDay = new Date(this.month.getFullYear(), currentMonth, 1)
      var lastDay = new Date(firstDay.getFullYear(), currentMonth + 1, 0);
      firstDay = firstDay.Format("yyyy-MM-dd");
      lastDay = lastDay.Format("yyyy-MM-dd");       
      let date =[firstDay,lastDay] 
      let month = date.join(',')

      //日充值
      let res = await Request.post("customer/dailyRecharge","query_list",{"date":this.date,"overview" : 1}); 
      if(res.code==0 && res.data.all != null ){
          this.points = res.data.all.bpt / 10000
          this.ftotal = res.data.all.rpt / 10000
      }      
      //收益统计-月
      let res2 = await Request.post("customer/income","query_list",{"date":month});
      if(res2.code==0 && res2.data.all != null){
          this.mbonustol = res2.data.all.profit / 10000
          this.mrechargetol = res2.data.all.points_consume_account / 10000
          this.mdeletol = res2.data.all.points_consume_gift / 10000
      }
       //收益统计-日
      let res3 = await Request.post("customer/income","query_list",{"date":this.date});   
      if(res3.code==0 && res3.data.all != null){
          this.bonustol = res3.data.all.profit/ 10000
          this.rechargetol = res3.data.all.points_consume_account / 10000
          this.deletol = res3.data.all.points_consume_gift/ 10000 
      }      

      // 图片对象
      const imageMap = {
        'ws筛活跃': this.wsskt,
        'ws筛性别': this.wsskt,
        'ws筛有效': this.wsskt,
        'Viber筛有效': this.viber,
        'Viber筛活跃': this.viber,
        'FB筛有效': this.fb,
        '领英筛有效': this.lin,
        'amazon筛有效': this.amazon,
        'INS筛有效': this.ins
      };

      let res4 = await Request.post("customer/businessType","query_list");
      if(res4.code==0 && res4.data.list != null){
        res4.data.list.forEach(element => {
          const imgg = imageMap[element.desc] || null;
          this.priceList.push({"id":element.desc,"name":element.unit_price/10000,"img":imgg})
        });
      }

      let res5 = await Request.post("customer/user", "query_list");
      this.list=[]
      if(res5.code==0 && res5.data.list != null){
        res5.data.list.forEach((item) => {
          this.list.push({"account":item.account,"recharge_points":item.recharge_points/10000,"bonus_points":item.bonus_points/10000,"ppoints":(item.recharge_points+item.bonus_points)/10000});
        })  
        this.totalCnt=res.data.total
      }
      console.log(this.list,this.totalCnt,"foihqweo")
    },    
  },
};
</script>
